{% extends 'base.htm' %}
{% from 'macros.htm' import venue_checkin_fmt, map_image, venue_cmds, addr_fmt, category_fmt, tips_fmt, specials_fmt, photo_fmt, name_fmt %}
{% set title = 'Venue Info' %}
{% block body %}

    {% set gmap_str = '' %}
    {% set dist_str = '' %}
    {% set location = venue.location %}
    {% if location.lat and location.lng %}
	{% set gmap_str = map_image(location.lat, location.lng) %}
	{% set distcompass = { 'lat' : location.lat, 'lon' : location.lng } | distcompass(lat, lon) %}
	{% set dist_str = '(%.1f mi %s)' | format(distcompass.dist|float, distcompass.compass|e) %}<br>
    {% endif %}

    <p>{{ venue.name|e }} {{ venue_cmds(venue, dist) }}
    <br>{{ addr_fmt(venue) }}

    {{ dist_str }}

    {% if venue.url %}
	<br><a href="{{ venue.url|urlencode }}">{{ venue.url|e }}</a>
    {% endif %}

    {{ gmap_str }}

    {% for cat in venue.categories %}
	{{ category_fmt(cat) }}
    {% endfor %}

    {% if venue.tags %}
	<p>Tags: {{ venue.tags | join(', ') | e }}
    {% endif %}

    {% if venue.stats %}
	<p>Checkins: {{ venue.stats.checkinsCount|e }} 
	<br>Users: {{ venue.stats.usersCount|e }}
    {% endif %}

    {% if venue.beenHere %}
	<br>Your checkins: {{ venue.beenHere.count|e }}
    {% endif %}

    {% if venue.hereNow %}
	<br>Here now: {{ venue.hereNow.count|e }}
    {% endif %}

    {% set mayor = venue.mayor %}
    {% if mayor %}
	{% set user = mayor.user %}
	{% if user %}
	    <p><img src="{{ user.photo.prefix|e ~ '36x36' ~ user.photo.suffix|e }}" class="usericon, lefticon" alt="">
	    {{ name_fmt(user, button=false) }} ({{ mayor.count|e }}x) is the mayor.
	    <br style="clear:both"> 
	{% else %}
	    <p>No mayor.
	{% endif %}
    {% endif %}

    {% set reasons = venue.reasons %}
    {% if reasons and reasons['items'] %}
	{% for reason in reasons['items'] %}
	    <p>{{ reason.message|e }}
	{% endfor %}
    {% endif %}

    {% set herenow = venue.hereNow %}
    {% if herenow %}
	{% if herenow.count > 0 %}
	    <p><b>Checked in here:</b>
	    {% for grp in herenow.groups %}
		{% for item in grp['items'] %}
		    {{ venue_checkin_fmt(item) }}
		{% endfor %}
	    {% endfor %}
	{% endif %}
    {% endif %}

    {{ tips_fmt(venue.tips) }}
    {{ specials_fmt(venue.specials) }}
    {{ specials_fmt(venue.specialsNearby, nearby=true) }}

    {% set photos = venue.photos %}
    {% set count = photos.count %}
    {% if count %}
	{% for grp in photos.groups %}
	    <p>-- {{ grp.name|e }}: {{ grp.count|e }} --
	    {% for item in grp['items'] %}
		{{ photo_fmt(item, venue_id = venue.id) }}
	    {% endfor %}
	{% endfor %}
    {% else %}
	<p>-- No photos --
    {% endif %}

    <p>
    <form style="margin:0; padding:0;" enctype="multipart/form-data" action="/addphoto" method="post">
    <input type="file" name="photo"><br>
    <input type="hidden" value="{{ venue.id|e }}" name="venid">
    <input type="submit" value="Add JPEG photo"><br>
    </form>

{% endblock %}

{# vim:set ft=htmldjango tw=0: #}
